package com.ruoyi.api.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.VideoUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzZhangjie;
import com.ruoyi.system.service.IDzZhangjieService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 章节信息Controller
 * 
 * @author ruoyi
 * @date 2022-09-01
 */
@RestController
@RequestMapping("/api/zhangjie")
public class DzZhangjieApiController extends BaseController
{
    @Autowired
    private IDzZhangjieService dzZhangjieService;

    /**
     * 查询章节信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DzZhangjie dzZhangjie)
    {
        startPage();
        List<DzZhangjie> list = dzZhangjieService.selectDzZhangjieListWeb(dzZhangjie);
        return getDataTable(list);
    }

    /**
     * 导出章节信息列表
     */
    @Log(title = "章节信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzZhangjie dzZhangjie)
    {
        List<DzZhangjie> list = dzZhangjieService.selectDzZhangjieListWeb(dzZhangjie);
        ExcelUtil<DzZhangjie> util = new ExcelUtil<DzZhangjie>(DzZhangjie.class);
        util.exportExcel(response, list, "章节信息数据");
    }

    /**
     * 获取章节信息详细信息
     */
    @GetMapping(value = "/{zjId}")
    public AjaxResult getInfo(@PathVariable("zjId") Long zjId)
    {
        return AjaxResult.success(dzZhangjieService.selectDzZhangjieByZjId(zjId));
    }

    /**
     * 新增章节信息
     */
    @Log(title = "章节信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzZhangjie dzZhangjie)
    {


        return toAjax(dzZhangjieService.insertDzZhangjie(dzZhangjie));
    }

    /**
     * 修改章节信息
     */
    @Log(title = "章节信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzZhangjie dzZhangjie)
    {
        return toAjax(dzZhangjieService.updateDzZhangjie(dzZhangjie));
    }

    /**
     * 删除章节信息
     */
    @Log(title = "章节信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{zjIds}")
    public AjaxResult remove(@PathVariable Long[] zjIds)
    {
        return toAjax(dzZhangjieService.deleteDzZhangjieByZjIds(zjIds));
    }
}
